describe('App.MoveConfirmController', function() {
    var controller,transfer;

    beforeEach(function() {
        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        transfer = App.OwnAccountTransfer.create();
        var t_moveHolderCtrl = App.MoveHolderController.create();

        App.MoveConfirmController.reopen({
            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
                this.set('controllers.moveHolder', t_moveHolderCtrl);
                this.set('transfer', transfer);
            }
        });
        spyOn(App.getSession(),'getCurrentTransfer').andReturn(transfer);
        controller = App.MoveConfirmController.create();
    });

    it("prepareController",function(){
        controller.prepareController();
    });

    it("confirmTransactionCallback - Other error", function(){

        var objE1 =  BreezeException.create({
            errorCode:'code',
            errorMessage: 'Error Messge'
        });

        spyOn(controller.get('transfer'),'set');
        spyOn(controller.get('controllers').get('alert'), 'showAlert').andCallFake(function(message, callback){
            callback();
        });

        spyOn(controller, 'transitionTo');
        spyOn(controller, 'hideLoading');

        controller.confirmTransferCallback([], objE1);

        expect(controller.hideLoading).toHaveBeenCalled();
        expect(controller.get('controllers').get('alert').showAlert).toHaveBeenCalledWith(objE1.getCustomErrorMessage('GENERAL_EXCEPTION'), jasmine.any(Function));
        expect(controller.transitionTo).toHaveBeenCalledWith('move.home');
        expect(controller.get('transfer').set).toHaveBeenCalledWith('transferResult', []);

    });

    it("confirmTransactionCallback - hasError == False", function(){

        var objE1 =  BreezeException.create({
            errorCode:'code',
            errorMessage: 'Error Messge'
        });

        spyOn(controller, 'hasError').andReturn(false);
        spyOn(controller, 'hideLoading');
        spyOn(controller, 'transitionTo');

        controller.confirmTransferCallback([]);

        expect(controller.hasError).toHaveBeenCalled();
        expect(controller.transitionTo).toHaveBeenCalledWith('move.summary');
        expect(controller.hideLoading).toHaveBeenCalled();
    });

    it("confirmTransactionCallback - ERR_ETAC_VALIDATION_FAILED", function(){

        var objE1 =  BreezeException.create({
            errorCode:'ERR_ETAC_VALIDATION_FAILED',
            errorMessage: 'Error Messge'
        });

        spyOn(controller, 'hasError').andReturn(true);
        spyOn(controller, 'hideLoading');
        spyOn(controller, 'otpErrorHandler');

        controller.confirmTransferCallback([], objE1);

        expect(controller.hasError).toHaveBeenCalledWith(objE1);
        expect(controller.otpErrorHandler).toHaveBeenCalledWith(objE1);
        expect(controller.hideLoading).toHaveBeenCalled();
    });



    it('secondBtnAction', function() {
        spyOn(controller.get('controllers').get('alert'), 'showAlert').andCallFake(function(message, callback){
            callback();
        });

        spyOn(controller, 'transitionTo');

        controller.secondBtnAction();

        expect(controller.get('controllers').get('alert').showAlert).toHaveBeenCalledWith(controller.get('i18nData.continueLaterMsg'), jasmine.any(Function));
        expect(controller.transitionTo).toHaveBeenCalledWith('move');

    })
});